package com.rongc.client.freight.business.mine.view.activity;

import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.error.VolleyError;
import com.rongc.client.core.network.code.HandleCode;
import com.rongc.client.core.network.http.RequestManager;
import com.rongc.client.core.utils.LogUtils;
import com.rongc.client.core.utils.StringUtils;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.BaseActivity;
import com.rongc.client.freight.business.mine.request.api.AboutApi;
import com.rongc.client.freight.utils.UtilMethod;

import org.json.JSONObject;

import butterknife.Bind;

/**
 * Created by ccqx on 2017/7/20.
 */

public class AboutActivity extends BaseActivity {
    @Bind(R.id.tv_content)
    TextView mTvContent;
    @Bind(R.id.tv_title)
    TextView mTvTitle;

    Response.Listener<JSONObject> respOrderListener = new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            if (HandleCode.requestSuccess()) {
                mTvTitle.setText(response.optString("title"));
                if(StringUtils.isNotEmpty(response.optString("content")))
                    if(response.optString("content").length()>10)
                        mTvContent.setText(response.optString("content"));
            } else {
                UtilMethod.dismissProgressDialog(AboutActivity.this);
            }
        }
    };

    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            LogUtils.i("error.getMessage(): " + error.getMessage());
            UtilMethod.dismissProgressDialog(AboutActivity.this);
        }
    };

    @Override
    public void initData() {
        RequestManager.getInstance().call(new AboutApi(new AboutApi.AboutParams(),
                respOrderListener, errorListener));
    }

    @Override
    public void initView() {
        initToolbar(R.string.setting_about_lable);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_about;
    }
}
